<?php
require_once('define.inc.php');

if(!class_exists('ADOConnection')) {
	require_once('../lib/adodb/adodb.inc.php');
}

if(!isset($ADODB_CACHE_DIR)) {
	$ADODB_CACHE_DIR = '../cache/';
}
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;


// create a connection
$conn = &ADONewConnection(DB_TYPE);
$conn->PConnect(DB_SERVER, DB_USER, DB_PWD, DB_NAME);
$conn->cacheSecs = 15;

// execute a query
function sql_query($sql, $limit_nb = 0, $limit_offset = 0)
{
	global $conn;

	if($limit_nb <> 0)
	{
		$sql_result = $conn->SelectLimit($sql, $limit_nb, $limit_offset);
	}
	else
	{
		//$sql_result = $conn->CacheExecute($sql);
		$sql_result = $conn->execute($sql);
	}

	if(!$sql_result)
	{
		print $conn->ErrorMsg() . '<br/>Query : ' . $sql;
	}

	return $sql_result;
}

function sql_query_uncached($sql, $limit_nb = 0, $limit_offset = 0)
{
	global $conn;

	if($limit_nb <> 0)
	{
		$sql_result = $conn->SelectLimit($sql, $limit_nb, $limit_offset);
	}
	else
	{
		$sql_result = $conn->execute($sql);
	}

	if(!$sql_result)
	{
		print $conn->ErrorMsg() . '<br/>Query : ' . $sql;
	}
	return $sql_result;
}

?>
